package com.hqyj.base.controller;

import com.hqyj.base.model.InfoGoods;
import com.hqyj.base.model.InfoSupplier;
import frame.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @ProjectName: ERP-System
 * @Package: com.hqyj.base.controller
 * @ClassName: InfoGoodsController
 * @Author: LiYi
 * @Date: 2021-09-08 9:11
 */

@Controller
@RequestMapping("/baseController")
public class InfoGoodsController extends BaseController {
    @RequestMapping("/good.do")
    public String queryAllByInfoUser(Model model){
        List<InfoGoods> infoGoods_db = infoGoodsService.queryAllByInfoGoods();
        model.addAttribute("infoGoods_db",infoGoods_db);
        return "view/base/infogoods/infoGoodsList";
    }


    @RequestMapping("/addInfoGoods.do")
    public String addInfoUser(Model model, InfoGoods infoGoods){
        infoGoodsService.addInfoGoods(infoGoods);
        System.out.println(infoGoods + "已经获取到前端对象");

        List<InfoSupplier> infoSuppliers = infoSupplierService.queryAllByInfoSupplier();
        for (InfoSupplier infoSupplier : infoSuppliers) {
            infoSupplier.getProvider();
        }
        model.addAttribute("infoSuppliers",infoSuppliers);




        List<InfoGoods> infoGoods_db = infoGoodsService.queryAllByInfoGoods();
        model.addAttribute("infoGoods_db",infoGoods_db);
        return "view/base/infogoods/infoGoodsList";
    }

    @RequestMapping("/deleteInfoGoodsById.do")
    public String deleteInfoUserById(Model model, String Id){
        int urlId = Integer.parseInt(Id);
        infoGoodsService.deleteInfoProductsById(urlId);
        List<InfoGoods> infoGoods_db = infoGoodsService.queryAllByInfoGoods();
        model.addAttribute("infoGoods_db",infoGoods_db);
        return "view/base/infogoods/infoGoodsList";
    }


    @RequestMapping("/updateInfoGoodsUI.do")
    public String queryInfoUserById(Model model, String Id){
        int urlId = Integer.parseInt(Id);
        InfoGoods infoGoods_db = infoGoodsService.queryInfoGoodsById(urlId);
        System.out.println("查看数据的InfoProducts对象" + infoGoods_db);
        model.addAttribute("infoGoods_db",infoGoods_db);
        return "view/base/infogoods/updateInfoGoods";
    }
    @RequestMapping("/updateInfoGoodsById.do")
    public String updateInfoUserById(Model model, InfoGoods infoGoods){
        System.out.println("查看修改的数据" + infoGoods);
        infoGoodsService.updateInfoGoodsById(infoGoods);
        List<InfoGoods> infoGoods_db = infoGoodsService.queryAllByInfoGoods();
        model.addAttribute("infoGoods_db",infoGoods_db);
        return "view/base/infogoods/infoGoodsList";
    }


    @RequestMapping("/queryFuzzyInfoGoods.do")
    public String queryFuzzyInfoSupplier(Model model, String keyword) {
        System.out.println("前端的Keyword" + keyword);
        List<InfoGoods> infoGoods_db = infoGoodsService.queryFuzzyInfoGoods(keyword);
        model.addAttribute("infoGoods_db",infoGoods_db);
        return "view/base/infogoods/infoGoodsList";
    }

}
